﻿using System;

namespace __Ts.Core.Plugin
{
    [Serializable]
    public abstract class PluginBase<Contract, Service, Plugin> : MarshalByRefObject,IPlugin
        where Service : Contract, new()
        where Plugin : new()
    {

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static IPlugin GetInstance()
        {
            if (_plugin == null)
            {
                _plugin = (IPlugin)new Plugin();
                _services = new Service();
            }
            return _plugin;
        }
        private static IPlugin _plugin = null;
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public object GetServices()
        {
            if (_services == null)
                _services = new Service();
            return _services;
        }
        private static object _services;
        /// <summary>
        /// 
        /// </summary>
        public abstract string PluginKey { get; }
        /// <summary>
        /// 
        /// </summary>
        public string Name
        {
            get { return this.GetType().Namespace; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string AssemblyPath
        {
            get { return this.GetType().Assembly.Location; }
        }

        /// <summary>
        /// 远程对象生命周期
        /// </summary>
        /// <returns></returns>
        public override object InitializeLifetimeService()
        {
            return null;
        }
    }
}
